# 模仿注册
from flask import Flask,abort,request,render_template

app = Flask(__name__)

# 如果浏览器发起请求 http://127.0.0.1:5000/register （get请求）  则跳转到 register.html
# 如果浏览器端是 通过 register.html 点击立即注册（post请求），则 获取表单内容
@app.route("/register",methods=["GET","POST"])
def register():
    if request.method == "GET":
        return render_template("register.html")
    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        password2 = request.form.get("password2")
        print(username)
        print(password)
        print(password2)
        if("聂茹凤"==username):
            abort(405)
            return None
        else:
            return "注册成功"

# 自定义异常
@app.errorhandler(405)
def handle_405_error(err):
    return render_template("405.html")

if __name__ == '__main__':
    app.run()